package com.example.exam.db;

import java.io.Serializable;
import java.util.List;

/**
 * 存放显示列表信息的包装类。
 * @author Rjk
 * */
public class PageInfoBean implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	//当前页码
	private int curPage;
	//一页显示的记录数
	private int perPage;
	//总页数
	private int totalPage;
	//记录总数
	private int totalRec;
	
	//起始行数
	private int startIndex;
	//结束行数
	private int lastIndex;
	
	//结果集存放List
	private List<? extends Object> recList;
	
	public int getCurPage() {
		return curPage;
	}
	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}
	
	public int getPerPage() {
		return perPage;
	}
	public void setPerPage(int perPage) {
		this.perPage = perPage;
	}
	
	public int getTotalPage() {
		return totalPage;
	}
	
	public int getTotalRec() {
		return totalRec;
	}
	public void setTotalRec(int totalRec) {
		this.totalRec = totalRec;
	}
	
	public List<? extends Object> getRecList() {
		return recList;
	}
	public void setRecList(List<? extends Object> recList) {
		this.recList = recList;
	}
	
	/**
	 * 计算总页数
	 */
	public void calTotalPages() {
	   if(totalRec % perPage == 0){
		   this.totalPage = totalRec / perPage;
	   }else{
		   this.totalPage= (totalRec / perPage) + 1;
	   }
	}
	
	/**
	 * 计算开始行数
	 */
		public void calStartIndex() {
			this.startIndex = (curPage - 1) * perPage;
		}

	public int getStartIndex() {
		return startIndex;
	}
	
	/**
	 *  计算结束时候的索引
	 */
	public void calLastIndex() {
	   if (totalRec < perPage) {
		   this.lastIndex = totalRec;
	   }else if((totalRec % perPage == 0) || (totalRec % perPage != 0 && curPage < totalPage)){
		   this.lastIndex = curPage * perPage;
       } else if(totalRec % perPage != 0 && curPage == totalPage){ //最后一页
           this.lastIndex = totalRec;
	   } 
	}
	
	public int getLastIndex() {
		return lastIndex;
	}
	
	public void calPageParam(){
		calTotalPages();
		calStartIndex();
		calLastIndex();
	}
	
}